import { createRouter, createWebHistory } from 'vue-router'
import Index from '@/views/index.vue'
import Sy from '@/views/sy.vue'
import Gwc from '@/views/gwc.vue'
import Fl from '@/views/fl.vue'
import Wd from '@/views/wd.vue'
import Dl from '@/views/dl.vue'
import Zc from '@/views/zc.vue'
import Ss from '@/views/ss.vue'
import Xq from '@/views/xq.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/', redirect: '/zc' },
    {
      path: '/index',

      component: Index,
      children: [
        {
          path: 'sy',

          component: Sy,
        },
        {
          path: 'gwc',

          component: Gwc,
        },
        {
          path: 'fl',

          component: Fl,
        },
        {
          path: 'wd',

          component: Wd,
        },

      ]
    },
       {
          path: '/dl',

          component: Dl,
        },
           {
          path: '/zc',

          component: Zc,
        },
            {
          path: '/ss',

          component: Ss,
        },
               {
          path: '/xq/:goods_id',

          component: Xq,
        },

  ],
})
router.beforeEach((to, from, next) => {
  if (to.fullPath == '/index/gwc' || to.fullPath == '/index/wd') {
    let token = localStorage.getItem('token');
    if (token) {
      next()
    }
    else {
      next('/dl')
    }
  }
  else {
    next()
  }

  // ...
  // 返回 false 以取消导航
  return false
})
export default router
